<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目编号：</label>
                                <input type="text" name="projectNo"/>
                            </li>
<!--                            <li>-->
<!--                                <label>项目名称：</label>-->
<!--                                <input type="text" name="projectName"/>-->
<!--                            </li>-->
                            <li>
                                <label>项目来源：</label>
                                <input type="text" name="projectSource"/>
                            </li>
<!--                            <li>-->
<!--                                <label>项目预算：</label>-->
<!--                                <input type="text" name="projectBudget"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>合同金额：</label>-->
<!--                                <input type="text" name="projectAmount"/>-->
<!--                            </li>-->
                            <li>
                                <label>项目进度：</label>
                                <input type="text" name="projectSchedule"/>
                            </li>
<!--                            <li>-->
<!--                                <label>项目调研: 0:否,1:是：</label>-->
<!--                                <input type="text" name="projectResearch"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>POC测试: 0:否,1:是：</label>-->
<!--                                <input type="text" name="pocTesting"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:management:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:management:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:management:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:management:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:management:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:management:remove')}]];
        var detailFlag = [[${@permission.hasPermi('system:management:detail')}]];
        var projectTypeDatas = [[${@dict.getType('sys_project_type')}]];
        var projectSourceDatas = [[${@dict.getType('sys_project_source')}]];
        var requirementTypeDatas = [[${@dict.getType('sys_requirement_type')}]];
        var projectScheduleDatas = [[${@dict.getType('sys_project_schedule')}]];
        var prefix = ctx + "project/management";
        var schedulePrefix =  ctx + "project/schedule";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                detailUrl: prefix + "/detail/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "项目管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'projectId',
                    title: '项目ID',
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'projectNo',
                    title: '项目编号'
                },
                {
                    field: 'projectType',
                    title: '项目类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(projectTypeDatas, value);
                    }
                },
                {
                    field: 'projectSource',
                    title: '项目来源',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(projectSourceDatas, value);
                    }
                },
                {
                    field: 'projectDescribe',
                    title: '项目描述'
                },
                {
                    field: 'projectBudget',
                    title: '项目预算'
                },
                {
                    field: 'requirementType',
                    title: '需求类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(requirementTypeDatas, value);
                    }
                },
                {
                    field: 'projectAmount',
                    title: '合同金额'
                },
                {
                    field: 'createBy',
                    title: '经办人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'projectSchedule',
                    title: '项目进度',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(projectScheduleDatas, value);
                    }
                },
                // {
                //     field: 'projectResearch',
                //     title: '项目调研: 0:否,1:是'
                // },
                // {
                //     field: 'pocTesting',
                //     title: 'POC测试: 0:否,1:是'
                // },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },
                {
                    field: 'taskId',
                    title: '任务编号',
                    visible: false
                },
                {
                    field: 'procInstId',
                    title: '流程实例',
                    visible: false
                },
                {
                    field: 'assignee',
                    title: '办理人',
                    visible: false
                },
                {
                    field: 'name',
                    title: '流程名称',
                    visible: false
                },
                {
                    field: 'formKey',
                    title: 'url',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detailTab(\'' + row.projectId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='edit("  + index + ")'><i class='fa fa-edit'></i>编辑</a> ");
                        more.push("<a class='btn btn-default btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='remove(" + index + ")'><i class='fa fa-remove'></i>删除</a> ");

                        if ($.common.equals(row.createBy, row.assignee)) {
                            more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='process(" + index + ")'><i class='fa fa-envelope-open'></i>办理</a> ");
                        }

                        if ($.common.isNotEmpty(row.procInstId)) {
                            more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='schedule(" + index + ")'><i class='fa fa-area-chart'></i>进度</a> ");
                        }

                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function detailTab(projectId) {
            $.get(schedulePrefix + "/detail/" + projectId, function (data) {
                if (data.data > 0) {
                    $.operate.detailTab(projectId);
                } else {
                    $.modal.msgError("流程未开始");
                }
            });
        }

        /**
         * 办理
         *
         * @param index
         */
        function process(index) {
            var row = $("#bootstrap-table").bootstrapTable('getData')[index];
            $.modal.openTab(row.name, row.formKey + "?taskid=" + row.taskId);
        }

        /**
         * 流程进度
         *
         * @param index
         */
        function schedule(index) {
            var row = $("#bootstrap-table").bootstrapTable('getData')[index];
            console.log($(window).width());
            console.log($(window).height());
            top.layer.open({
                type: 2,
                area: [ ($(window).width() - 600) + 'px',  ($(window).height()) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "进度",
                content: "/flow/monitor/traceProcess/" + row.procInstId,
                btn: ['关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                cancel: function(index) {
                    return true;
                }
            });
        }

        function edit(index) {
            var row = $("#bootstrap-table").bootstrapTable('getData')[index];
            $.operate.edit(row.projectId);
        }

        function remove(index) {
            var row = $("#bootstrap-table").bootstrapTable('getData')[index];
            $.operate.remove(row.projectId);
        }
    </script>
</body>
</html>